/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package detonadores;

import Controladores.ControladorInsertar;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Augusto Andrade
 */
@WebServlet(name = "ProcesarApoyo", urlPatterns = {"/ProcesarApoyo"})
public class ProcesarApoyo extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            
            int DecideUno=(int)request.getSession().getAttribute("DecideUno"); 
            
            if(DecideUno==1){
            ControladorInsertar ControlFinanciero=new ControladorInsertar();    
            String DatoFinanciero=request.getParameter("DatoFinanciero");
            String InsertarF=null;
            if(DatoFinanciero.equals("Ingresar")){
            out.println("<script type='text/javascript'>"
            +"alert('No se ingreso ningun Apoyo Financiero');"
            +"pagina='Apoyo.jsp';"
            +"function redireccionar(){location.href=pagina;}" 
            +"setTimeout ('redireccionar()', 0);"
            +"</script>");
            }else{
        InsertarF="0,'"+DatoFinanciero.toUpperCase()+"'";
        ControlFinanciero.setContenidoFinanciero(InsertarF);
        ControlFinanciero.IngresarApoyoFinanciero();
        if(ControlFinanciero.getContenidoFinanciero()==true){
        out.println("<script type='text/javascript'>"
        +"alert('El Apoyo Financiero se ingresó Correctamente');"
        +"pagina='Apoyo.jsp';"
        +"function redireccionar(){location.href=pagina;}" 
        +"setTimeout ('redireccionar()', 0);"
        +"</script>");
        }else{
        out.println("<script type='text/javascript'>"
        +"alert('El Apoyo Financiero NO se ingresó Correctamente vuelva a intentarlo');"
        +"pagina='Apoyo.jsp';"
        +"function redireccionar(){location.href=pagina;}" 
        +"setTimeout ('redireccionar()', 0);"
        +"</script>");
        }
            }
            }else if(DecideUno==2){
            ControladorInsertar ControlAcademico=new ControladorInsertar();    
            String DatoAcademico=request.getParameter("DatoAcademico");
            String InsertarA=null;
            if(DatoAcademico.equals("Ingresar")){
            out.println("<script type='text/javascript'>"
             +"alert('No se ingreso ningun Apoyo Académico');"
             +"pagina='Apoyo.jsp';"
             +"function redireccionar(){location.href=pagina;}" 
             +"setTimeout ('redireccionar()', 0);"
             +"</script>");
            }else{
            InsertarA="0,'"+DatoAcademico.toUpperCase()+"'";
        ControlAcademico.setContenidoAcademico(InsertarA);
        ControlAcademico.IngresarApoyoAcademico();
        if(ControlAcademico.getContenidoAcademico()==true){
        out.println("<script type='text/javascript'>"
        +"alert('El Apoyo Académico se ingresó Correctamente');"
        +"pagina='Apoyo.jsp';"
        +"function redireccionar(){location.href=pagina;}" 
        +"setTimeout ('redireccionar()', 0);"
        +"</script>");
        }else{
        out.println("<script type='text/javascript'>"
        +"alert('El Apoyo Académico NO se ingresó Correctamente vuelva a intentarlo');"
        +"pagina='Apoyo.jsp';"
        +"function redireccionar(){location.href=pagina;}" 
        +"setTimeout ('redireccionar()', 0);"
        +"</script>");
        }
            }
            }
            
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
